﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace TS_XY_Train_Repaire.ToolSystem
{
    public partial class Tool_System_ToolPosEdit_Form : DevExpress.XtraEditors.XtraForm
    {
        private TS_ToolPos m_oToolPos = new TS_ToolPos();

        public TS_ToolPos OToolPos { get => m_oToolPos; set => m_oToolPos = value; }

        public Tool_System_ToolPosEdit_Form()
        {
            InitializeComponent();
        }

        private void Tool_System_ToolPosEdit_Form_Load(object sender, EventArgs e)
        {
            te_name.Text = m_oToolPos.SName;
            te_parent.Text = m_oToolPos.SParentName;

            lc_parent.Visible = false;
            te_parent.Visible = false;

            if (m_oToolPos.IParentID > 0)
            {
                lc_parent.Visible = true;
                te_parent.Visible = true;
            }
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            m_oToolPos.SName = te_name.Text;
            if (m_oToolPos.IID <= 0)
            {
                if (ToolDataMgr.GetInstance().AddToolPos(m_oToolPos))
                {
                    this.DialogResult = DialogResult.OK;
                }
            }
            else
            {
                if (ToolDataMgr.GetInstance().ModifyToolPos(m_oToolPos))
                {
                    this.DialogResult = DialogResult.OK;
                }
            }
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
    }
}